package com.zycfc.zsf.boot.distributedlock.zk.comparator;

import java.util.*;
import com.zycfc.zsf.boot.util.text.*;

public class LockNodeComparator implements Comparator<String>
{
    private String lockNodePre;
    
    public LockNodeComparator(final String lockNodePre) {
        this.lockNodePre = lockNodePre;
    }
    
    @Override
    public int compare(final String o1, final String o2) {
        return getLockNodeNameNumber(o1, this.lockNodePre).compareTo(getLockNodeNameNumber(o2, this.lockNodePre));
    }
    
    private static String getLockNodeNameNumber(final String lockNode, final String lockNodePre) {
        if (CheckUtil.isEmpty((Object)lockNodePre)) {
            return lockNode;
        }
        final int lockNodePreIndex = lockNode.lastIndexOf(lockNodePre);
        return (lockNodePreIndex >= 0) ? lockNode.substring(lockNodePreIndex + lockNodePre.length()) : lockNode;
    }
}
